VideoPlayer
The VideoPlayer view integrates a powerful AVPlayer backend with a simple, customizable front-end UI for playing video and audio content. With this setup, you can easily load media, control playback, handle events, and even add custom overlays.
Overview
VideoPlayer requires an AVPlayer instance, which you configure to load your media, control its playback (play, pause, stop), and respond to events like when the video is ready or ends. The overlay prop allows you to place interactive UI elements over the video content, below any system playback controls.
Key points:
- Control playback through the
AVPlayerinstance passed intoVideoPlayer. - Add custom UI elements on top of the video using
overlay. - Listen for events like
onReadyToPlay,onEnded, oronErrorto react to media lifecycle states.
Basic Usage
First, create and configure the AVPlayer instance:
Then, use the VideoPlayer view in your UI:
This displays the video with your custom controls positioned at the bottom-left corner.
Example Scenario
Imagine you want a video with custom controls and automatic replay:
This setup:
- Loads and plays a local video file immediately when ready.
- Automatically replays the video once it ends.
- Provides custom pause/resume controls overlaid on the bottom-right corner.
Summary
The VideoPlayer component, powered by an AVPlayer instance, gives you fine-grained control over video playback in your app. From adjusting volume and playback speed to handling buffering states and errors, and even layering your own UI controls over the video, the VideoPlayer component and AVPlayer class allow for a rich and interactive media experience.
